from transformers import BertTokenizer, BertForSequenceClassification, pipeline

model_name = "bert-base-chinese"
# 项目根路径
model_dir = "/Users/wupeng/pythonProjects/huggingface/models/bert-base-chinese/models--bert-base-chinese/snapshots/c30a6ed22ab4564dc1e3b2ecbf6e766b0611a33f"
# 加载模型
model = BertForSequenceClassification.from_pretrained(model_dir)
# 加载分词器
tokenizer = BertTokenizer.from_pretrained(model_dir)
# 加载管道
pipe = pipeline("text-classification", model=model, tokenizer=tokenizer, device="cpu")
# 生成文本，分类模型
text = pipe("你好，我是一个程序员，")
# [{'label': 'LABEL_0', 'score': 0.6293583512306213}]
print(text)
